package cn.chenc.framework.jpa.service;

import cn.chenc.framework.jpa.exception.ServiceException;
import cn.chenc.framework.jpa.model.PageInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 　@description: TODO
 * 　@author secret
 * 　@date 2021/6/5 23:31
 *
 */
public interface BaseService<T, ID extends Serializable> {
    T save(T t) throws ServiceException;

    List<T> save(Iterable<T> entities) throws ServiceException;

    T update(T t) throws ServiceException;

    T saveOrUpdate(ID id, T t) throws ServiceException;

    T get(ID id) throws ServiceException;

    void delete(ID id) throws ServiceException;

    void delete(T t) throws ServiceException;

    void deleteAll(Iterable<T> entities) throws ServiceException;

    void deleteBatchByIds(Collection<ID> ids) throws ServiceException;

    boolean exists(ID id) throws ServiceException;

    long count() throws ServiceException;

    List<T> findAll() throws ServiceException;

    List<T> findAll(T t) throws ServiceException;

    List<T> findAll(T t, Sort sort) throws ServiceException;

    List<T> findAll(Sort sort) throws ServiceException;

    List<T> findAll(Specification<T> specification) throws ServiceException;

    Page<T> findAll(Pageable pageable) throws ServiceException;

    Page<T> findAll(T t, Pageable pageable) throws ServiceException;

    Page<T> findPage(Specification<T> specification, Pageable pageable) throws ServiceException;

    T getOneByObject(T t) throws ServiceException;

    List<T> getListByObject(T t) throws ServiceException;

    List<T> getListByObject(T t, Sort sort) throws ServiceException;

    Page<T> getListByObject(T t, Pageable pageable) throws ServiceException;

    List<T> getListBySql(String sql) throws ServiceException;

    List<T> getListBySql(String sql, Class<T> clzss) throws ServiceException;

    PageInfo getListBySql(String sql, PageInfo pageable) throws ServiceException;

    List<Map<String, Object>> getListMapBySql(String sql) throws ServiceException;

    PageInfo getListMapBySql(String sql, PageInfo pageable) throws ServiceException;

    Map<String, Object> getSingleMapBySql(String sql) throws ServiceException;

    int insertBySql(String sql) throws ServiceException;

    int updateBySql(String sql) throws ServiceException;

    int deleteBySql(String sql) throws ServiceException;

    int executeBySql(String sql) throws ServiceException;

    int executeBySql(List<String> sqls) throws ServiceException;

    int getCountBySql(String sql, Map<String, Object> searchMap) throws ServiceException;

    Pageable getPageable(Map<String, Object> params);

    PageInfo getPage(Map<String, Object> params);
}
